package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DsClassStu;
import com.ruoyi.system.service.IDsClassStuService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程学生中间Controller
 *
 * @author tyro
 * @date 2025-03-23
 */
@RestController
@RequestMapping("/system/stu")
public class DsClassStuController extends BaseController
{
    @Autowired
    private IDsClassStuService dsClassStuService;

    /**
     * 查询课程学生中间列表
     */
    @PreAuthorize("@ss.hasPermi('system:stu:list')")
    @GetMapping("/list")
    public TableDataInfo list(DsClassStu dsClassStu)
    {
        startPage();
        List<DsClassStu> list = dsClassStuService.selectDsClassStuList(dsClassStu);
        return getDataTable(list);
    }

    /**
     * 导出课程学生中间列表
     */
    @PreAuthorize("@ss.hasPermi('system:stu:export')")
    @Log(title = "课程学生中间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DsClassStu dsClassStu)
    {
        List<DsClassStu> list = dsClassStuService.selectDsClassStuList(dsClassStu);
        ExcelUtil<DsClassStu> util = new ExcelUtil<DsClassStu>(DsClassStu.class);
        util.exportExcel(response, list, "课程学生中间数据");
    }

    /**
     * 获取课程学生中间详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:stu:query')")
    @GetMapping(value = "/{classId}")
    public AjaxResult getInfo(@PathVariable("classId") Long classId)
    {
        return success(dsClassStuService.selectDsClassStuByClassId(classId));
    }

    /**
     * 新增课程学生中间
     */
    @PreAuthorize("@ss.hasPermi('system:stu:add')")
    @Log(title = "课程学生中间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DsClassStu dsClassStu)
    {
        return toAjax(dsClassStuService.insertDsClassStu(dsClassStu));
    }

    /**
     * 修改课程学生中间
     */
    @PreAuthorize("@ss.hasPermi('system:stu:edit')")
    @Log(title = "课程学生中间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DsClassStu dsClassStu)
    {
        return toAjax(dsClassStuService.updateDsClassStu(dsClassStu));
    }

    /**
     * 删除课程学生中间
     */
    @PreAuthorize("@ss.hasPermi('system:stu:remove')")
    @Log(title = "课程学生中间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{classIds}")
    public AjaxResult remove(@PathVariable Long[] classIds)
    {
        return toAjax(dsClassStuService.deleteDsClassStuByClassIds(classIds));
    }

    /**
     * 查询学生所在课程
     */
    @GetMapping("/students/{studentId}")
    @PreAuthorize("@ss.hasPermi('system:stu:remove')")
    public AjaxResult getStudentsByStudentId(@PathVariable("studentId") String studentId)
    {
        return success(dsClassStuService.selectDsClassStuByStudentId(studentId));
    }

    /**
     * 查询学生所在课程
     */
    @PostMapping("/listClass")
    @PreAuthorize("@ss.hasPermi('system:stu:list')")
    public TableDataInfo listClass(@RequestBody DsClassStu dsClassStu)
    {
        startPage();
        List<DsClassStu> list = dsClassStuService.selectDsClassStuList(dsClassStu);
        return getDataTable(list);
    }
}
